package org.example.entity;

import org.example.Component;

import java.util.ArrayList;
import java.util.List;

public class Group extends Component {

    private String name;
    private List<Component> componentList = new ArrayList<>();

    @Override
    public void add(Component component) {
        componentList.add(component);
    }

    @Override
    public void share(String thing) {
        List<Component> memberList = this.getComponentList();
        //只向成员转发
        for(Component member : memberList){
            if(member instanceof Member){
                member.share(thing);
            }
        }
    }

    public Group() {
    }
    public Group(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Group{" +
                "name='" + name + '\'' +
                ", componentList=" + componentList +
                '}';
    }

    public List<Component> getComponentList() {
        return componentList;
    }

    public void setComponentList(List<Component> componentList) {
        this.componentList = componentList;
    }
}
